#! /bin/sh

# A helper script to expand incessant usage of variables from the postinst script to help figure out what the actual paths are!

DEBIAN_INSTALL_PREFIX=/opt
VERSION=16.20.00.00
MAJORVER=`echo $VERSION | awk -F. '{printf("%02d",$1)}'`
MINORVER=`echo $VERSION | awk -F. '{printf("%02d",$2)}'`
SHRTVER_NODOT=${MAJORVER}${MINORVER}
SHRTVER=${MAJORVER}.${MINORVER}
OSLIB32=/usr/lib32
OSLIB64=/usr/lib
PROFILE=/etc/profile                # Login file for Bourne/Korn shell users
LOGIN=/etc/csh.login                # Login file for C-shell users
MAXLINELEN=75
DESTINATION_DIR="${DEBIAN_INSTALL_PREFIX}/teradata/client/${SHRTVER}"
LIBDIR="${DESTINATION_DIR}/lib"
LIBDIR64="${DESTINATION_DIR}/lib64"
INST_DIR=$DEBIAN_INSTALL_PREFIX
TDODBC_INSTALL_DIR=${INST_DIR}/teradata/client/$SHRTVER
TDODBC_32_INSTALL_DIR=${TDODBC_INSTALL_DIR}/odbc_32
TDODBC_64_INSTALL_DIR=${TDODBC_INSTALL_DIR}/odbc_64
TDODBC_32_INI_FILE=${TDODBC_32_INSTALL_DIR}/odbc.ini
TDODBC_64_INI_FILE=${TDODBC_64_INSTALL_DIR}/odbc.ini
TDODBC_INST_32_INI_FILE=${TDODBC_32_INSTALL_DIR}/odbcinst.ini
TDODBC_INST_64_INI_FILE=${TDODBC_64_INSTALL_DIR}/odbcinst.ini
PKG_ODBC_32_DIR=${INST_DIR}/teradata/client/ODBC_32
TDODBC_ODBC32_INI=${PKG_ODBC_32_DIR}/odbc.ini
TDODBC_ODBC32_INI_INST=${PKG_ODBC_32_DIR}/odbcinst.ini
PKG_ODBC_64_DIR=${INST_DIR}/teradata/client/ODBC_64
TDODBC_ODBC64_INI=${PKG_ODBC_64_DIR}/odbc.ini
TDODBC_ODBC64_INI_INST=${PKG_ODBC_64_DIR}/odbcinst.ini
TDODBC_LIB64_DIR=lib64
TDODBC_LIB_DIR=lib
odbc_32_dir="odbc_32"
odbc_64_dir="odbc_64"
ODBC_32_DIR="ODBC_32"
ODBC_64_DIR="ODBC_64"

for VAR in DEBIAN_INSTALL_PREFIX VERSION MAJORVER MINORVER SHRTVER_NODOT SHRTVER OSLIB32 OSLIB64 PROFILE LOGIN MAXLINELEN DESTINATION_DIR LIBDIR LIBDIR64 INST_DIR TDODBC_INSTALL_DIR TDODBC_32_INSTALL_DIR TDODBC_64_INSTALL_DIR TDODBC_32_INI_FILE TDODBC_64_INI_FILE TDODBC_INST_32_INI_FILE TDODBC_INST_64_INI_FILE PKG_ODBC_32_DIR TDODBC_ODBC32_INI TDODBC_ODBC32_INI_INST PKG_ODBC_64_DIR TDODBC_ODBC64_INI TDODBC_ODBC64_INI_INST TDODBC_LIB64_DIR TDODBC_LIB_DIR odbc_32_dir odbc_64_dir ODBC_32_DIR ODBC_64_DIR; do
    eval VAL=\$$VAR
    sed -i -e "s+\${$VAR}+$VAL+g" -e "s+\$$VAR+$VAL+g" postinst
done
